#-*- coding:utf-8 -*-
import re

f=open("PINK.txt","r")
source=""
try:
    while (1):
        line= f.readline()
        if not line:
            break
        source+=line
finally:
    f.close()
REGEX={
    "head":"<font[^>]*>",
    "attr":"color=\"([^\"]+)\"",
    "foot":"<[^>]font>",
    "all":"<[^>]*>"
}

colorArr,resultArr=[],[]
for obj in re.findall(REGEX["head"],source, re.M|re.I):
    colorArr.append(re.sub("\=",":",re.sub("\"","",re.search(REGEX["attr"],obj).group()))+";")
textArr=re.sub(REGEX["all"],"",re.sub(REGEX["head"],"",re.sub(REGEX["foot"],",",source))).split(',')
textArr.pop()
row=50
cID=0
resultText=""
for i in range(len(textArr)):
    if cID<row:
        cID+=len(textArr[i])
        resultText+="%c"+textArr[i]
    else:
        resultArr.append(resultText)
        resultText=""
        cID=0
        cID+=len(textArr[i])
        resultText+="%c"+textArr[i]
print colorArr
print textArr
print resultArr

f=open("PINK_res.txt","w")
res="console.log(\""
# sId=0
# for i in range(len(resultArr)):
#     if resultArr[i]:
#         res="console.log(\""+resultArr[i]+"\""
#         for c in range(sId,(sId+resultArr[i].count("%"))):
#             res+=",\""+colorArr[c]+"\""
#         res+=");"
#         sId+=resultArr[i].count("%")
#         f.write(res)
for i in range(len(resultArr)):
    if resultArr[i]:
        res+=resultArr[i]+"\\n"
res+="\""
for c in range(len(colorArr)):
    res += ",\"" + colorArr[c] + "\""
res += ");"
f.write(res)
f.close()